printDT(BrCasesFormatted,
rownames(BrCasesFormatted)
)
dz <-
SPDeathsReg %>%
rownames_to_column(var = "NovaColuna") %>%
arrange_at(vars(last_col()), desc) %>%
select(NovaColuna, everything()) %>%
column_to_rownames("NovaColuna") %>%
t %>%
as_tibble %>%
mutate_all(~ . - lag(.)) %>%
mutate(Dates = as.Date(colnames(SPDeathsReg), format = "%m/%d/%y") ) %>%
select(Dates, everything()) %>%
mutate_if(~ any(is.na(.)), ~ if_else(is.na(.), 0, .))
dw <-
do.call(cbind, lapply(colnames(dz)[-1], function(x) TTR::SMA(dz[,x], 7))) %>%
as_tibble %>%
rename_all(~ paste0('M',colnames(dz)[-1])) %>%
mutate_if(~ any(is.na(.)), ~ if_else(is.na(.), 0, .))
dh <-
cbind(dz, dw) %>%
as_tibble %>%
filter(Dates >= as.Date("2020-03-20"))
f2 <- list(family = 'Old Standard TT, serif', size = 16, color = ("#4c1112"))
plots <-
lapply(colnames(dh)[2:18], function(x){
expr <- paste0("~", "`", x, "`")
mexpr <- paste0("~", "`", "M", x, "`")
legm <- paste0("Moving average of ", x)
t <- dh[nrow(dh),x]
tt <- SPDeathsReg[x,ncol(SPDeathsReg)]
a <- list(
text = paste0(x," - Total Deaths:",tt," - Last data:",t),
font = f2,
xref = "paper",
yref = "paper",
yanchor = "bottom",
xanchor = "center",
align = "center",
x = 0.5,
y = 1,
showarrow = FALSE
)
plot_ly(dh, x = ~Dates) %>%
add_trace(y = as.formula(expr), type = 'bar', color = I("firebrick4")) %>%
add_trace(y = as.formula(mexpr), type = 'scatter', mode = 'lines', color = I("black") ) %>%
layout(showlegend = FALSE, annotations = a)
})
names(plots) <- colnames(dz)[-c(1, length(dz))]
p <- subplot(plots, nrows = 7, shareX = FALSE, shareY = FALSE)
p
TABELA_R_eff <- dw %>%
mutate_all(~ .x/lag(.x,7)) %>%
mutate_if(~ any(is.infinite(.x)),~ replace(.x,is.infinite(.x),0)) %>%
mutate_if(~ any(is.na(.x)),~ replace(.x,is.na(.x),0)) %>%
mutate_all(~ round(.x,1)) %>%
rownames_to_column() %>%
pivot_longer(-rowname) %>%
pivot_wider(names_from=rowname, values_from=value) %>%
rename_all(~ c("RAs", format(seq.Date(from=as.Date("2020-02-25"),to=Sys.Date(),by="days"),"%d/%m/%y"))) %>%
select("RAs",last_col(50:0))
m <- TABELA_R_eff %>%
filter(row_number() != 4) %>%
column_to_rownames("RAs") %>%
as.matrix()
colorScale <- data.frame(z=c(0,0.17,0.17,0.33,0.33,0.66,0.66,1),col=c("#008000","#008000","#FFFF00","#FFFF00","#ffa500", "#ffa500", "#FF0000", "#FF0000"))
colorScale$col <- as.character(colorScale$col)
p <- plot_ly(x=colnames(m), y=rownames(m), z = m, zmin=0 , zmax=3, zsmooth=FALSE, ygap =0.5,xgap =0.5, colorscale=colorScale, type = "heatmap")
p